<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .big {
            width: 550px;
            height: 600px;
            margin: 0 auto;
        }

        .top {
            width: 550px;
            height: 60px;
            border: 1px solid black;
            margin: 0 auto;
            background-color: gainsboro;
        }

        .bot {
            width: 550px;
            height: 500px;
            margin: 0 auto;
            background-color: aliceblue;
        }

        li {
            width: 100px;
            height: 50px;
            list-style-type: none;
            float: left;
            float: top;
            /* background-color: antiquewhite; */

        }

        .on {
            color: rgba(253, 9, 9, 0.968);
            /* background-color: aquamarine; */
        }

        .item {
            display: none;
        }
    </style>
</head>

<body>
    <div class="big">
        <div class="top">
            <ul>
                <li class="on">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="bot">
            <div class="item" style="display: block">
                商品介绍
            </div>
            <div class="item">
                规格与包装
            </div>
            <div class="item">
                售后保障
            </div>
            <div class="item">
                商品评价
            </div>
            <div class="item">
                手机社区
            </div>
        </div>
    </div>
    <script>
        let ul = document.querySelector('ul');
        let lis = ul.querySelectorAll('li');
        let items = document.querySelectorAll('.item');
        for (let i = 0; i < lis.length; i++) {
            //给li设置索引号
            lis[i].setAttribute('index', i);

            lis[i].onclick = function () {
                for (let i = 0; i < lis.length; i++) {
                    lis[i].className = '';
                }
                lis[i].className = 'on';
                //下面的显示
                let index = this.getAttribute('index');
                console.log(index);
                for (let i = 0; i < items.length; i++) {
                    items[i].style.display = 'none';
                }
                items[index].style.display = 'block';
            }
        }


    </script>
</body>

</html>